﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Golem.Indexer.Data.SearchResult>" %>
<%@ Import Namespace="WebSearch.Helpers" %>
<% 
    Dictionary<long, List<Golem.Indexer.Data.FileDescriptor>> resultset = new Dictionary<long, List<Golem.Indexer.Data.FileDescriptor>>();
    
    foreach (var file in Model.Files)
    {
        if (!resultset.ContainsKey((long) file.MachineId)) {
            resultset.Add((long) file.MachineId, new List<Golem.Indexer.Data.FileDescriptor>());
        }
        resultset[(long) file.MachineId].Add(file);
    }
           
foreach (var entry in resultset) 
{
    var machine = Model.Machines[entry.Key];
    %>
    
    <div class="machine">
        <h2><% if (machine.Hostname != String.Empty)
            { %><%:machine.Hostname %> <span class="ip"><%:machine.IP %></span><% }
            else { Response.Write(machine.IP); } %></h2>

        <div class="files">
        <% foreach (var file in entry.Value)
           {
              %>
              <div class="file <%:file.Type.ToString().ToLower() %>">
                <a href="<%:Html.FileUri(file.FullName) %>"><%:Html.FileLabel(file.FullName) %></a>
              </div>
              <%
           } %>
        </div>
    </div>

    <%
    
}
%>